var querykey = 'jxlxmanagelist';

function init() {
	var url = context
			+ '/system/objectarg.do?method=list&querykey=' + querykey;

	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			if (o.totalCount > 0) {
				Ext.each(o.queryList, function(item) {
					var tr = document
							.getElementById('lxlist')
							.insertRow(document.getElementById('lxlist').rows.length);

					if (viewItems && viewItems.length > 0) {
						Ext.each(viewItems, function(im) {
									var td = tr.insertCell(tr.cells.length);

									renderCell(td, im, eval('item.' + im));

								})
					}

					var td = tr.insertCell(tr.cells.length);
					td.className = 'td0';
					td.align = 'center';
					td.width = '15%';
					td.innerHTML = '<a href="#" onclick="javascript:handleEdit(\''
							+ item.ID
							+ '\');">编辑</a>&nbsp;<a href="#" onclick="javascript:handleDel(\''
							+ item.ID + '\');">删除</a>';
				});
			}
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

function clearTable(t) {
	for (var i = document.getElementById(t).rows.length - 1; i >= 0; i--) {
		if (i > 0) {
			document.getElementById(t).deleteRow(i);
		}
	}
}

/**
 * 删除对象信息
 * 
 * @param {}
 *            id
 */
function handleDel(id) {
	var url = context + '/system/objectcreator.do?method=deleteS&ids=' + id
			+ '&querykey=' + querykey;

	Ext.Ajax.request({
				// 请求地址
				url : url,
				scriptTag : true,
				// 成功时回调
				success : function(response, options) {
					var json = response.responseText;
					var o = Ext.util.JSON.decode(json);
				},
				failure : function(response, options) {
					clearTable('lxlist');
					init();
				}
			});
}

/**
 * 编辑对象
 * 
 * @param {}
 *            id
 */
function handleEdit(id) {
	window.location.href = context
			+ '/system/objectcreator.do?method=edit4json&id=' + id + '&querykey=' + querykey;
}

function renderCell(td, key, value) {
	td.className = 'td0';

	if (key == 'XFTIME' || key == 'XJTIME') {
		td.innerHTML = formatDate(value);
	} else {
		td.innerHTML = value;
	}
}